package com.hyj.springai.repository;

import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class InMemoryChatHistoryRepository implements ChatHistoryRepository{

    private final Map<String,List<String>> chatMemory = new HashMap<>();

    @Override
    public void save(String type,String chatId) {
        if (!chatMemory.containsKey(type)) {
            chatMemory.put(type,new ArrayList<>());
        }
        if (chatMemory.get(type).contains(chatId)) {
            return;
        }
        chatMemory.get(type).add(chatId);
    }

    @Override
    public List<String> getChatIds(String type) {
        return chatMemory.getOrDefault(type,List.of());
    }
}
